package cn.shuangliang.contract.web;

import cn.shuangliang.contract.model.Admin;
import cn.shuangliang.contract.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.Writer;

/**
 * @author oldliu
 * @since 1.0
 */
@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public String login(String userName, String userPass, HttpSession session){
       //resposne.getWriter
        //故意让他报错！
        //userPass=userPass.substring(20);

        Admin login = adminService.login(userName, userPass);
        if(login!=null){
            session.setAttribute("USER_LOGIN",login);
            //return "forward:/loginok.jsp";
            return "redirect:/loginok.jsp";
        }

        return "forward:/fail.jsp";
    }
}
